<?php
/**
 * memcache缓存类
 * User: cory
 * Date: 2017/3/17
 * Time: 16:26
 */

class CacheMemcache implements CacheInterface{
    private $_linkHandle;
    private $cache_sign = '';//缓存标识，用来标志相应的语言缓存

    public function set($key,$val){
        return $this->_linkHandle->set($this->cache_sign.'_'.$key,$val);
    }

    /**
     * 得到缓存数据
     * @param $key
     * @return mixed
     */
    public function get($key){
        return $this->_linkHandle->get($this->cache_sign.'_'.$key);
    }

    /**
     * 删除缓存
     * @param $key
     * @return int
     */
    public function remove($key){
        return $this->_linkHandle->delete($key);
    }

    /** 初始化
     * @param $config_array
     * @return bool
     */
    public function connect($config_array,$lang){
        $this->_linkHandle = new Memcache();
        $this->cache_sign = $lang;
        return $this->_linkHandle->connect($config_array['host'], $config_array['port']);
    }

    /**
     * 关闭连接
     */
    public function close(){
        return $this->_linkHandle->close();
    }

}